﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}
<script>
    var organizeid = " @LeSoft.Application.Code.OperatorProvider.Provider.Current().CompanyId", _State = "", _WeekTypeId = "";
    var keyValue = request('keyValue'); var Week = request("Week"); var Count = request("Count"); var Year = request("Year");
    var Type = request('Type');
    $(function () {
        if (!!keyValue) {
            $("#CS_Heidden").attr("hidden", "hidden");
            $(".Hid").attr("hidden", "hidden");
            $(".toolbar").attr("hidden", "hidden");
            GetGridByTime();
        }
        else {
            InitialPage();
            GetTree();
            GetGrid();
        }
    })
   
    function InitialPage() {
        //layout布局
        $('#layout').layout({
            applyDemoStyles: true,
            onresize: function () {
                $(window).resize()
            }
        });
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth(($('.gridPanel').width()));
                $("#gridTable").setGridHeight($(window).height() - 181.5);

            }, 200);
             e.stopPropagation();

        });
        //初始化时间
        $("#StartTime").val("@DateTime.Now.AddDays(-DateTime.Now.Day+1).ToString("yyyy-MM-dd")");
        $("#EndTime").val("@DateTime.Now.AddMonths(1).AddDays(- DateTime.Now.Day).ToString("yyyy-MM-dd")");
        //组织机构
        $("#OrganizeId").ComboBoxTree({
            url: "../../BaseManage/Organize/GetTreeJsonById",
            description: "==选择所属机构==",
            height: "250px",
            click: function (data) {
                organizeid = data.id;
                $('#btn_Search').trigger("click");
            }
        }); 
        $("#OrganizeId").ComboBoxSetValue(organizeid);
        $("#State").ComboBox({
            //  url: " ",
            data: [{ "key": "1", "value": "待处理" }, { "key": "2", "value": "派单中" }, { "key": "3", "value": "进行中" }, { "key": "4", "value": "已完成" }, { "key": "5", "value": "已取消" }, { "key": "6", "value": "已退单" }],
            id: "key",
            text: "value",
            description: "=选择工单状态=", 
            click: function (item) {
                _State = item.id;
                $('#btn_Search').trigger("click");
            }
        });
        //初始化时间 
        $("#StartTime").val("@DateTime.Now.AddDays(-DateTime.Now.Day+1).ToString("yyyy-MM-dd")");
        $("#EndTime").val("@DateTime.Now.AddMonths(1).AddDays(- DateTime.Now.Day).ToString("yyyy-MM-dd")");
        $("#time_horizon").ComboBox({
            data: [{ "key": 2, "value": "上周" }, { "key": 1, "value": "本周" }, { "key": 4, "value": "上月" }, { "key": 3, "value": "本月" }, { "key": 5, "value": "本年" }],
            id: "key",
            text: "value",
            //description: "==请选择==",
            click: function (item) {
                
                var value = item.attr('data-value'); 
                switch (value) {
                    case "1"://本周
                        $("#StartTime").val("@DateTime.Now.AddDays(1 - DateTime.Now.DayOfWeek.GetHashCode()).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddDays(7 - DateTime.Now.DayOfWeek.GetHashCode()).ToString("yyyy-MM-dd")");
                        break;
                    case "2"://上周
                        $("#StartTime").val("@DateTime.Now.AddDays(1 - DateTime.Now.DayOfWeek.GetHashCode()-7).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddDays(7 - DateTime.Now.DayOfWeek.GetHashCode()-7).ToString("yyyy-MM-dd")");
                        break;
                    case "3"://本月
                        $("#StartTime").val("@DateTime.Now.AddDays(-DateTime.Now.Day+1).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddMonths(1).AddDays(- DateTime.Now.Day).ToString("yyyy-MM-dd")");
                        break;
                    case "4"://上月
                        $("#StartTime").val("@DateTime.Now.AddDays(-DateTime.Now.Day + 1).AddMonths(-1).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")");
                        break;
                    case "5"://本年
                        $("#StartTime").val("@DateTime.Now.AddDays(-DateTime.Now.DayOfYear + 1).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddMonths(12 - DateTime.Now.Month + 1).AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")");
                        break;
                    default:
                        break;
                }
                $("#SelectedStartTime").html($("#StartTime").val());
                $("#SelectedEndTime").html($("#EndTime").val());
                $('#btn_Search').trigger("click");
            }
        });
        $("#time_horizon").ComboBoxSetValue(3);
 
    }

    function GetTree() {
        var item = {
            height: $(window).height() - 55.5,
            url: "../../PropertyManage/CS_DeviceMaintance/GetWorkTypeTreeJson",
            onnodeclick: function (item) {
                _WeekTypeId = item.id;
                $('#btn_Search').trigger("click");
            }
        };
        //初始化
        $("#itemTree1").treeview(item);
    }

    function GetGrid() {
        var selectedRowIndex = 0;
        $gridTable = $("#gridTable");
        var queryJson = {
            OrganizeId: organizeid,
            State: $("#State").attr('data-value'),
            WeekTypeId: _WeekTypeId,
            StartTime: $("#StartTime").val(),
            EndTime: $("#EndTime").val(),
            Code: $("#Code").val(),
        };
        $gridTable.jqGrid({
            url: "../../PropertyManage/CS_DeviceMaintanenceBill/GetWeekBillList",
            postData: { queryJson: JSON.stringify(queryJson) },
            datatype: "json",
            height: $(window).height() - 141,
            autowidth: true,
            colModel: [
                { label: "主键", name: "Id", hidden: true },
                { label: "所属类型", name: "TypeName", index: "TypeName", width: 200, align: "center", sortable: false },
                { label: "项目编号", name: "Code", index: "Code", width: 200, align: "center", sortable: false },
                { label: "项目名称", name: "ItemName", index: "ItemName", width: 200, align: "center", sortable: false },
                { label: "计划开始时间", name: "BeginDate", index: "BeginDate", width: 200, align: "center", sortable: false, formatter: "date", formatoptions: { newformat: 'Y-m-d' } },
                { label: "计划结束时间", name: "EndDate", index: "EndDate", width: 200, align: "center", sortable: false, formatter: "date", formatoptions: { newformat: 'Y-m-d' } },
                {
                    label: "计划执行人", name: "ExecRoleId", index: "execRoleId", width: 200, align: "center", sortable: false,
                    formatter: function (cellvalue, options, rowObject) {
                        return cellvalue != null ? top.clientpostData[cellvalue].FullName : "";
                    }
                },
                {
                    label: "完成状态", name: "State", index: "State", width: 100, align: "center", sortable: false,
                    formatter: function (cellvalue, options, rowObject) {
                        var Msg = "";
                        switch (cellvalue) {
                            case 1: Msg = "<span  class='label label-danger'>待处理</span>";
                                break;
                            case 2: Msg = "<span  class='label label-success'>派单中</span>";
                                break;
                            case 3: Msg = "<span  class='label label-info'>进行中</span>";
                                break;
                            case 4: Msg = "<span  class='label label-info'>已完成</span>";
                                break;
                            case 5: Msg = "<span  class='label label-info'>已取消</span>";
                                break;
                            case 6: Msg = "<span  class='label label-info'>已退单</span>";
                                break;
                            default: Msg = "---";
                                break;
                        }
                        return Msg;
                    }
                },
               { label: "执行开始时间", name: "ExecBeginDate", index: "ExecBeginDate", width: 200, align: "center", sortable: false },
                { label: "执行终止时间", name: "ExecEndDate", index: "ExecEndDate", width: 200, align: "center", sortable: false },
            ],
            viewrecords: true, 
            rowNum: 30,
            rowList: [30, 50, 100],
            pager: "#gridPager",
            sortname: 'Date',
            sortorder: 'desc',
            rownumbers: true, 
            onSelectRow: function (status) {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            gridComplete: function () { 
            }
        });
        //查询事件
        $("#btn_Search").click(function () { 
            var queryJson = {
                OrganizeId: organizeid,
                State: $("#State").attr('data-value'),
                WeekTypeId: _WeekTypeId,
                StartTime: $("#StartTime").val(),
                EndTime: $("#EndTime").val(),
                Code: $("#Code").val(),

            };
            $("#gridTable").jqGrid('setGridParam', {
                url: "../../PropertyManage/CS_DeviceMaintanenceBill/GetWeekBillList",
                postData: { queryJson: JSON.stringify(queryJson) },
            }).trigger('reloadGrid');
        });
        $("#btn_Reset").click(function () {
            $("#Code").val("");
            $("#EndTime").val("");
            $("#StartTime").val("");
        })

    }
    function btn_add() { //新增
        dialogOpen({
            id: "Form",
            title: '新增计划项目',
            url: '/PropertyManage/CS_DeviceMaintanenceBill/Form',
            width: "1100px",
            height: "750px",
            callBack: function (iframeId) {
                top.frames["Form"].AcceptClick();
            }
        })
    }
    function btn_edit() { //编辑
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (checkedRow(keyValue)) {
            dialogOpen({
                id: "Form",
                title: '编辑计划项目',
                url: '/PropertyManage/CS_DeviceMaintanenceBill/Form?keyValue=' + keyValue,
                width: "1100px",
                height: "750px",
                callBack: function (iframeId) {
                    top.frames["Form"].AcceptClick();
                }
            })
        }
    }
    function btn_delete()
    {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (checkedRow(keyValue)) {
            $.RemoveForm({
                url: "../../PropertyManage/CS_DeviceMaintanenceBill/RemoveWeekBillForm",
                param: { keyValue: keyValue },
                success: function (data) {
                    $('#btn_Search').trigger("click");
                }
            })
        }
    }
</script>
<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-west" id="CS_Heidden">
        <div class="west-Panel">
            <div class="panel-Title" style="padding:0px; text-align:center;">工作项目列表</div>
            <div id="itemTree1">
            </div>
        </div>
    </div>
    <div class="ui-layout-center">
        <div class="center-Panel">
            <div class="titlePanel">
                <div class="title-search Hid">
                    <table>
                        <tr>
                            <td>查询条件</td>
                            <td><div id="OrganizeId" type="selectTree" style="width:170px; margin-left:10px;" class="ui-select "></div></td>
                            <td style="padding-left: 10px;">
                                <div class="ui-filter" style="width: 200px;">
                                    <div class="ui-filter-text">
                                        <strong id="SelectedStartTime">@DateTime.Now.AddDays(-DateTime.Now.Day + 1).ToString("yyyy-MM-dd")</strong> 至 <strong id="SelectedEndTime">@DateTime.Now.AddMonths(1).AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")</strong>
                                    </div>
                                    <div class="ui-filter-list" style="width: 350px;">
                                        <table class="form" id="filter-form">
                                            <tr>
                                                <th class="formTitle">工单时间：</th>
                                                <td class="formValue">
                                                    <div style="float: left; width: 45%;">
                                                        <input id="StartTime" readonly type="text" value="2017-07-01" class="form-control input-wdatepicker" onfocus="WdatePicker()">
                                                    </div>
                                                    <div style="float: left; width: 10%; text-align: center;">至</div>
                                                    <div style="float: left; width: 45%;">
                                                        <input id="EndTime" readonly type="text" value="2017-07-31" class="form-control input-wdatepicker" onfocus="WdatePicker()">
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="formTitle">工单编号：</td>
                                                <td class="formValue">
                                                    <input id="Code" type="text" class="form-control">
                                                </td>
                                            </tr>

                                        </table>
                                        <div class="ui-filter-list-bottom">
                                            <a id="btn_Reset" class="btn btn-default">&nbsp;重&nbsp;&nbsp;置</a>
                                            <a id="btn_Search" class="btn btn-primary">&nbsp;查&nbsp;&nbsp;询</a>
                                        </div>
                                    </div>
                                </div>
                            </td>
                            <td  style="padding-left: 10px;">
                                <div id="time_horizon" type="selectTree" class="ui-select" style="width: 60px;"></div>
                            </td>
                            <td style="padding-left: 10px;">
                                <div id="State" type="select" class="ui-select" style="width: 120px;"></div>
                            </td>

                        </tr>

                    </table>

                </div>

                <div class="toolbar">
                    <div class="btn-group">
                        <a id="lr-replace" class="btn btn-default CS_Heidden"  onclick="reload(); "><i class="fa fa-refresh"></i>&nbsp;刷新</a>
                        <a id="lr-add" class="btn btn-default CS_Heidden" onclick="btn_add()"><i class="fa fa-plus"></i>&nbsp;新增</a>
                        <a id="lr-edit" class="btn btn-default CS_Heidden" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑</a>
                        <a id="lr-delete" class="btn btn-default CS_Heidden" onclick="btn_delete()"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
                        <div class="btn-group">
                            <a id="lr-delete" class="btn btn-default CS_Heidden" data-toggle="dropdown"><i class="fa fa-reorder"></i>&nbsp;更多操作<span class="caret"></span></a>


                        </div>

                    </div>

                </div>
            </div>


            <div class="gridPanel">
                <table id="gridTable"></table>
                <div id="gridPager"></div>
            </div>

        </div>
    </div>
</div>
